package com.wswy.wzcx.ui.wzdb

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import com.wswy.wzcx.api.Api
import com.wswy.wzcx.model.license.UserCarInfo
import com.wswy.wzcx.model.wzdb.WzdbCreateResp
import com.wswy.wzcx.module.base.Resource
import com.wswy.wzcx.module.base.SingleLiveData
import com.wswy.wzcx.module.base.UserViewModel
import com.wswy.wzcx.module.base.onResult
import com.wswy.wzcx.ui.data.WZDBMode

class WzdbViewModel : UserViewModel() {


    private val wzListLiveData  = MutableLiveData<Resource<List<WZDBMode>?>>()
    private val wzdbCreateLiveData = SingleLiveData<Resource<WzdbCreateResp?>>()

    lateinit var userCarInfo: UserCarInfo

    var defaultChooseUid : String?=null


    //加载违章代办列表
    fun loadList(){

        addRun(Api.get().fetchWZDBData(userCarInfo).onResult(wzListLiveData))

    }

    fun submitWz(list:String?){
        addRun(Api.get().submitWZDBList(list).onResult({
            it?.run {
                listIds = list
            }
            wzdbCreateLiveData.postValue(Resource.success(it))
        },{
            wzdbCreateLiveData.postValue(Resource.error(it))
        }))
    }


    fun getWzListLiveData(): LiveData<Resource<List<WZDBMode>?>> = wzListLiveData

    fun getWzdbCreateLiveData():LiveData<Resource<WzdbCreateResp?>> = wzdbCreateLiveData

}